package com.zb.framework.config;

import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration;
import org.springframework.cloud.client.discovery.composite.reactive.ReactiveCompositeDiscoveryClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author fujianjian
 * @date 2023/3/1 14:00
 **/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(NacosDiscoveryProperties.class)
@ConditionalOnDiscoveryEnabled
@ConditionalOnNacosDiscoveryEnabled
@AutoConfigureAfter({ NacosDiscoveryAutoConfiguration.class,
        ReactiveCompositeDiscoveryClientAutoConfiguration.class })
@AutoConfigureBefore({ ReactiveCommonsClientAutoConfiguration.class })
public class ZeusNacosLoadBalancerConfiguration {

    @Bean
    public ZeusNacosServiceDiscovery zeusNacosServiceDiscovery(
            NacosDiscoveryProperties properties, NacosServiceManager manager) {
        return new ZeusNacosServiceDiscovery(properties, manager, "H1");
    }

    @Bean
    public ZeusNacosReactorDiscoveryClient zeusNacosReactorDiscoveryClient(
            ZeusNacosServiceDiscovery zeusNacosServiceDiscovery) {
        return new ZeusNacosReactorDiscoveryClient(zeusNacosServiceDiscovery);
    }


}
